<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>APP</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/common.css" />
    <link rel="stylesheet" type="text/css" href="../../css/login.css">
    <link rel="stylesheet" type="text/css" href="../../css/font/iconfont.css">
</head>
<body>
    <div id="wrap">
    	<div id="header" class="header">
            <div class="left"><a href="#"><i class="icon iconfont icon-fanhui"></i></a></div>	
			<div class="center"><p>提现</p></div>
			<div class="right"><a><i class="icon iconfont icon-sousuo"></i></a></div>
        </div>
        <div id="main">
            <div class="plate">
            	<div class="row">
            		<div class="left"><span>帐号</span></div>
            		<div class="left"><input id="account" type="text" placeholder="请输入帐号"></div>
            	</div>
            	<div class="row">
            		<div class="left"><span>金额</span></div>
            		<div class="left"><input id="amount" type="text" placeholder="请输入金额"></div>
            	</div>
            	
            	<div class="row">
            		<div class="left"><span>户名</span></div>
            		<div class="left"><input id="accName" type="text" placeholder="请输入户名"></div>
            	</div>
            	<div class="row">
            		<div class="left"><span>开户行</span></div>
            		<div class="left"><input id="bank" type="text" placeholder="请输入开户行"></div>
            	</div>
            	
            	<div class="row">
            		<div class="left"><span>手机号</span></div>
            		<div class="left"><input id="tele" readOnly="true" type="text" placeholder="请输入手机号"></div>
            	</div>
            	
            	<div class="row">
            		<div class="rows">
	            		<div class="left"><span>验证码</span></div>
	            		<div class="left"><input id="code" type="text" placeholder="请输入短信验证码"></div>
	            		<a id="smsCode" onclick="getSmsCode()">获取验证码</a>
	            	</div>
            	</div>
            	
            	<div class="btn-row">
            		<a href="#" class="btn" onclick="cash()">提现</a>
            	</div>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/zepto.js"></script>
<script type="text/javascript">
    var count = 0; //间隔函数，1秒执行
    var InterValObj; //timer变量，控制时间
    var icode = '';
    var tele ='';
    var validBal = 0;
    
    $.ajax({
        url : "http://www.aiyi5.com/getUser",
        type : "POST",
        async : false,
        dataType: 'json',
        error : function(errorMsg) {
            
        },
        success : function(data) {
            tele = data.tele;
            validBal = data.bal - data.freezBal;
        }
    });
    
    function getSmsCode() {
        if(count > 0){
            return;
        }
        count = 60;

        var d = {
            tele : tele
        }

        $.ajax({
            url : "http://www.aiyi5.com/getCashCode",
            type : "POST",
            data : d,
            async : false,
            dataType: 'json',
            error : function(errorMsg) {

            },
            success : function(data) {
                if (data.code == '0') {
                    $("#smsCode").html(count + "秒");
                    InterValObj = window.setInterval(SetRemainTime, 1000);
                } else {
                    alert('发送失败');
                }
            }
        });
    }

    function SetRemainTime() {
        if (count == 0) {
            window.clearInterval(InterValObj);//停止计时器
            $("#smsCode").html("获取验证码");
        } else {
            count--;
            $("#smsCode").html(count + "秒");
        }
    }
    
    function cash(){
        var d = {
            account: $("#account").val(),
            amount: $("#amount").val(),
            accName: $("#accName").val(),
            bank: $("#bank").val(),
            code: $("#code").val()
        }
        $.ajax({
            url : "http://www.aiyi5.com/cash",
            type : "POST",
            data : d,
            async : false,
            dataType: 'json',
            error : function(errorMsg) {

            },
            success : function(data) {
                alert(data.msg);
            }
        });
    }
    apiready = function(){
       
    }
</script>
</html>